gene=TP53

class_list=("IM" "IGC" "DGC")

for gene in `cat ${Images_path}/selectGCClone/GCClone_gene.all_record.list ${mutsig_check_path}/smg.list | sed 's/\r//' | grep -v Gene | sort -u`
do

####################################################################################
## scissor鉴定突变相关细胞
## 只在发生突变的样本中鉴定
## IM/IGC/DGC均鉴定
${Rscript_singlecell} ${scripts_path}/singlecell/scissor_cell_OurData.Standard.R \
--sample_list_file ${config_path}/tumor_normal.class.list \
--sample_list_single_file  ${config_path}/singleCell_Sample.list \
--sample_list_public_file ${work_dir}/public_ref/combine/MutationInfo.combine.tsv \
--rsem_file ${mRNA_path}/CombineTPM.DNAUse.NJMU_TCGA.tsv \
--maf_public_file ${work_dir}/maf_public/All_use.addVAF.maf \
--single_cell_file ${work_dir}/public_ref/singleCell/njmu/epiall_nor_PCA_50_RE0.5.Rdata \
--out_path ${Images_path}/singleCell_MutSample/${gene} \
--gene ${gene}


####################################################################################
## 差异表达分析
## 目前只算了DGC的TP53
for class in ${class_list[@]}
do

## 跑完p值计算
if [ -f ${Images_path}/singleCell_MutSample/${gene}/Scissor_STAD_${gene}_mutation.${class}.All.tsv ]
then
${Rscript_singlecell} ${scripts_path}/singlecell/differexpression.Standard.R \
--single_cell_file ${Images_path}/singleCell_MutSample/${gene}/Scissor_STAD_${gene}_mutation.${class}.CellRate.All.RData \
--gene ${gene} \
--cds_file ~/ref/PCAWG_Elements/web_hg19/gc19_pc.cds.use.bed \
--pathway_path ~/ref/Pathway/ \
--out_path ${Images_path}/singleCell_MutSample/${gene}/${class}/Diff

## GSEA
${Rscript_gsea} ${scripts_path}/singlecell/gsea.Standard.R \
--input_file ${Images_path}/singleCell_MutSample/${gene}/${class}/Diff/DiffGene.tsv \
--pathway_path ~/ref/Pathway/ \
--out_path ${Images_path}/singleCell_MutSample/${gene}/${class}/Diff/GSEA
fi

done

####################################################################################
## 提取感兴趣的基因
gene=`cat ${Images_path}/selectGCClone/GCClone_gene.all_record.list ${mutsig_check_path}/smg.list | sed 's/\r//' | grep -v Gene | sort -u | tr '\n' '|' | sed 's/|$//'`
## 单细胞的样本
singleSample=`cat ${config_path}/singleCell_Sample.list | sed '1d' | awk -F'\t' '{if($5!=""){print $2}}' | tr '\n' '|' | sed 's/|$//'`
## 检查是否存在样本，有多个感兴趣的基因发生突变
cat ${MutationTime_path}/result/All_CCF_mutTime.tsv | grep -w -E ${gene}  | grep -w -E ${singleSample} | grep -v -E "Intron|Silent"

## 每个基因在该样本中分别鉴定突变相关细胞，推断其克隆簇
## DGC、JZGCWES165(JR008D)
## ERBB2、TP53、PIK3CA
gene_list=("TP53" "PIK3CA" "ERBB2")
use_sample=JR008D
use_class=DGC
for gene in ${gene_list[@]}
do
${Rscript_singlecell} ${scripts_path}/singlecell/scissor_cell_OurData.Standard_UseSample.R \
--sample_list_file ${config_path}/tumor_normal.class.list \
--sample_list_single_file  ${config_path}/singleCell_Sample.list \
--sample_list_public_file ${work_dir}/public_ref/combine/MutationInfo.combine.tsv \
--rsem_file ${mRNA_path}/CombineTPM.DNAUse.NJMU_TCGA.tsv \
--maf_public_file ${work_dir}/maf_public/All_use.addVAF.maf \
--single_cell_file ${work_dir}/public_ref/singleCell/njmu/epiall_nor_PCA_50_RE0.5.Rdata \
--out_path ${Images_path}/singleCell_MutSample/${use_sample}/ \
--gene ${gene} \
--use_sample ${use_sample} \
--use_class ${use_class}
done

<<EOF
## DGC、JZGCWES29(JZ751D)
## TP53、RHOA
## 无法鉴定RHOA突变型的细胞
gene_list=("TP53" "RHOA")
use_sample=JZ751D
use_class=DGC
for gene in ${gene_list[@]}
do
${Rscript_singlecell} ${scripts_path}/singlecell/scissor_cell_OurData.Standard_UseSample.R \
--sample_list_file ${config_path}/tumor_normal.class.list \
--sample_list_single_file  ${config_path}/singleCell_Sample.list \
--sample_list_public_file ${work_dir}/public_ref/combine/MutationInfo.combine.tsv \
--rsem_file ${mRNA_path}/CombineTPM.DNAUse.NJMU_TCGA.tsv \
--maf_public_file ${work_dir}/maf_public/All_use.addVAF.maf \
--single_cell_file ${work_dir}/public_ref/singleCell/njmu/epiall_nor_PCA_50_RE0.5.Rdata \
--out_path ${Images_path}/singleCell_MutSample/${use_sample}/ \
--gene ${gene} \
--use_sample ${use_sample} \
--use_class ${use_class}
done
EOF

## 整合三个基因的聚类结果
